package com.party.core.service.enterpriseservice.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.common.utils.UUIDUtils;
import com.party.core.dao.read.enterpriseservice.EpServiceCategoryReadDao;
import com.party.core.dao.write.enterpriseservice.EpServiceCategoryWriteDao;
import com.party.core.model.enterpriseservice.EpCategory;
import com.party.core.model.enterpriseservice.EpServiceCategory;
import com.party.core.service.enterpriseservice.IEpServiceCategoryService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @program: party
 * @description: 服务类型关系service实现
 * @author: Hua Qunhao
 * @create: 2019-01-08 16:09
 */

@Service("EpServiceCategoryService")
public class EpServiceCategoryService implements IEpServiceCategoryService {

    @Autowired
    private EpServiceCategoryReadDao epServiceCategoryReadDao;

    @Autowired
    private EpServiceCategoryWriteDao epServiceCategoryWriteDao;


    @Override
    public String insert(EpServiceCategory epServiceCategory) {
        String uuid = UUIDUtils.generateRandomUUID();
        if (Strings.isNullOrEmpty(epServiceCategory.getId())) {
            epServiceCategory.setId(uuid);
        }
        boolean result = epServiceCategoryWriteDao.insert(epServiceCategory);
        if (result) {
            return epServiceCategory.getId();
        }
        return null;
    }

    @Override
    public boolean update(EpServiceCategory epServiceCategory) {
        return epServiceCategoryWriteDao.update(epServiceCategory);
    }

    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return epServiceCategoryWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return epServiceCategoryWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return epServiceCategoryWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return epServiceCategoryWriteDao.batchDelete(ids);
    }

    @Override
    public EpServiceCategory get(String id) {
        return epServiceCategoryReadDao.get(id);
    }

    @Override
    public List<EpServiceCategory> listPage(EpServiceCategory epServiceCategory, Page page) {
        return epServiceCategoryReadDao.listPage(epServiceCategory,page);
    }

    @Override
    public List<EpServiceCategory> list(EpServiceCategory epServiceCategory) {
        return epServiceCategoryReadDao.listPage(epServiceCategory,null);
    }

    @Override
    public List<EpServiceCategory> batchList(Set<String> ids, EpServiceCategory epServiceCategory, Page page) {
        if (CollectionUtils.isEmpty(ids)){
            return Collections.EMPTY_LIST;
        }
        return epServiceCategoryReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public List<EpCategory> queryCategoryListbyServiceId(String serviceId) {
        return epServiceCategoryReadDao.queryCategoryListbyServiceId(serviceId);
    }

    @Override
    public EpServiceCategory findByCategorybycIdandsId(EpServiceCategory EpServiceCategory) {
        return epServiceCategoryReadDao.findByCategorybycIdandsId(EpServiceCategory);
    }

    @Override
    public void deleteEpCategoryBycIdandsid(EpServiceCategory epServiceCategory) {
        epServiceCategoryWriteDao.deleteEpCategoryBycIdandsid(epServiceCategory);
    }
}
